#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int dp[5000][5000];

int calo(string& s, string& t)
{
    int m = s.size();
    int n = t.size();
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (s[i - 1] == t[j - 1])
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    return dp[m][n];
}


int main() 
{
    string s, t;
    cin >> s;
    cin >> t;

    int length = calo(s, t);
    cout << length << endl;

    return 0;
}
